package com.bj.dz.service.impl;

import com.bj.dz.entity.ElectricityMadeHourse;
import com.bj.dz.mapper.ElectricityMadeHourseMapper;
import com.bj.dz.service.ElectricityMadeHourseService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ElectricityMadeHourseServiceImpl implements ElectricityMadeHourseService {

    @Resource
    private ElectricityMadeHourseMapper electricityMadeHourseMapper;

    public ElectricityMadeHourse getElectricityMadeHourseById(Integer id){
        return electricityMadeHourseMapper.getElectricityMadeHourseById(id);
    }

    public List<ElectricityMadeHourse>	getElectricityMadeHourseListByMap(Map<String,Object> param){
        return electricityMadeHourseMapper.getElectricityMadeHourseListByMap(param);
    }

    public Integer getElectricityMadeHourseCountByMap(Map<String,Object> param){
        return electricityMadeHourseMapper.getElectricityMadeHourseCountByMap(param);
    }

    @Transactional
    public boolean addElectricityMadeHourse(ElectricityMadeHourse electricityMadeHourse){
            return electricityMadeHourseMapper.insertElectricityMadeHourse(electricityMadeHourse)>0?true:false;
    }

    @Transactional
    public boolean modifyElectricityMadeHourse(ElectricityMadeHourse electricityMadeHourse){
        return electricityMadeHourseMapper.updateElectricityMadeHourse(electricityMadeHourse)>0?true:false;
    }

    @Transactional
    public boolean deleteElectricityMadeHourseById(Integer id){
        return electricityMadeHourseMapper.deleteElectricityMadeHourseById(id)>0?true:false;
    }

    public Page<ElectricityMadeHourse> queryElectricityMadeHoursePageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = electricityMadeHourseMapper.getElectricityMadeHourseCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ElectricityMadeHourse> electricityMadeHourseList = electricityMadeHourseMapper.getElectricityMadeHourseListByMap(param);
        page.setRows(electricityMadeHourseList);
        return page;
    }

}
